import datetime
from django.db import models
from django.contrib.auth.models import User
import time
import uuid
from django.utils.timezone import now


# Create your models here.
# class Person(models.Model):
#     f = models.CharField(max_length=10)
#     l = models.CharField(max_length=10)
#     s = models.CharField(default='sss', max_length=10)


class UserExtend(models.Model):
    """用户扩展表"""
    user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
    # 与User表关联的时候会自动生成
    # userId = models.AutoField('用户ID', primary_key=True, editable=False)
    # email = models.EmailField('邮件', default='**@**.com', blank=True)
    telephone = models.CharField('电话', default=0000, max_length=11, blank=True)
    isDelete = models.BooleanField('是否删除', default=False)
    isValid = models.BooleanField('是否有效', default=True)
    roleType = models.IntegerField('角色类型', default=1)
    userLevel = models.IntegerField('用户等级', default=1)
    score = models.IntegerField('分数', default=0)
    signature = models.CharField('签名', max_length=200, default='Personal signature!')
    createTime = models.DateTimeField('创建时间', auto_now_add=True)
    updateTime = models.DateTimeField('更新时间', auto_now=True)
    token = models.CharField('登录态', default=0, max_length=500)
    # tokenExpireTime = models.DateTimeField('登录态过期时间', default=datetime.datetime.now())
    tokenExpireTime = models.DateTimeField('登录态过期时间', default=now)
    # null = models.CharField('备用', max_length=200, default='备用!')


class Article(models.Model):
    """资讯文章表"""
    title = models.CharField('title', max_length=500, default="title")
    subtitle = models.CharField('subtitle', max_length=100, default="subtitle")
    introduction = models.CharField('introduction', max_length=200, default="introduction")
    content = models.CharField('content', max_length=1000, default="content")
    link = models.CharField('link', max_length=300, default="link")
    keyword = models.CharField('keyword', max_length=20, default="keyword")
    classfy = models.CharField('classfy', max_length=20, default="classfy")
    batchNo = models.CharField('batchNo', max_length=1000, default=1)
    hits = models.IntegerField('0', default=0)
    viewnum = models.IntegerField('0', default=0)
    ontop = models.BooleanField('ontop', default=False)
    iselite = models.BooleanField('iselite', default=False)
    isdeleted = models.BooleanField('isdeleted', default=False)
    onshelf = models.BooleanField('onshelf', default=False)
    author = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
    # articleimgpath = models.ImageField(upload_to='media/introducer/articleimgs/', default='media/introducer/articleimgs/')
    # articlevideopath = models.ImageField(upload_to='media/introducer/articleimgs/', default='media/introducer/articleimgs/')
    create_time = models.DateTimeField('created time', auto_now_add=True)
    update_time = models.DateTimeField('updated time', auto_now=True)


class Reply(models.Model):
    """资讯文章评论表"""
    article_id = models.ForeignKey(Article, on_delete=models.CASCADE)
    article_author_id = models.ForeignKey(User, on_delete=models.CASCADE)
    article_author_username = models.CharField('article_author_username', max_length=100)
    article_comment_id = models.IntegerField('article_comment_id', default=0)
    article_comment_username = models.CharField('article_comment_username', default='commentusername', max_length=100)
    comment = models.CharField('comment content', default='null comment', max_length=10000)
    canbereply = models.BooleanField('canbereply', default=True)
    issoncomment = models.BooleanField('issoncomment', default=False)
    isdeleted = models.BooleanField('isdeleted', default=False)
    classfy = models.CharField('classfy', max_length=20, default="classfy")
    create_time = models.DateTimeField('created time', auto_now_add=True)
    update_time = models.DateTimeField('updated time', auto_now=True)


class video(models.Model):
    """视频表"""
    author = models.CharField('author', max_length=2000, default="author")
    avatorLink = models.CharField('avatorLink', max_length=1000, default="avatorLink")
    title = models.CharField('title', max_length=2000, default="title")
    videoLink = models.CharField('videoLink', max_length=1000, default="videoLink")
    videoPic = models.CharField('videoPic', max_length=1000, default="videoPic")
    videoTimeLong = models.CharField('videoTimeLong', max_length=1000, default=1)
    classfy = models.CharField('classfy', max_length=100, default="classfy")
    pubDate = models.DateTimeField('published time')
    pubLocation = models.CharField('pubLocation', max_length=100, default="classfy")
    hitRank = models.IntegerField('hitRank', default=1)
    view = models.IntegerField('view', default=1)
    favorite = models.IntegerField('favorite', default=1)
    batchNo = models.CharField('batchNo', max_length=1000, default=1)
    ontop = models.BooleanField('ontop', default=False)
    iselite = models.BooleanField('iselite', default=False)
    isdeleted = models.BooleanField('isdeleted', default=False)
    onshelf = models.BooleanField('onshelf', default=False)
    create_time = models.DateTimeField('created time', auto_now_add=True)
    update_time = models.DateTimeField('updated time', auto_now=True)


